<template>
  <div class="tab-control">
    <div class="tab-control-item" :class="{active:index === currentIndex}" v-for="(item,index) in titles" :key="index" @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
import {ref} from "vue";

export default {
  name: "TabControl",
  props:{
    titles:{
      type:Array,
      default() {
        return [];
      }
    }
  },
  setup(props, context){
    let currentIndex = ref(0);
    const itemClick = (index) => {
      currentIndex.value = index
      context.emit('tabClick', index)
    }

    return {
      currentIndex,
      itemClick
    }
  }
}
</script>

<style scoped>
.tab-control {
  display: flex;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  text-align: center;
  /*background: ;*/
  /*width: 100%;*/
  position: sticky;
  top: 45px;
  background: #ffffff;
  z-index: 9;
}

.tab-control-item {
flex: 1;
}

.tab-control-item span {
padding: 5px;
}
.tab-control-item.active {
  color: var(--color-tint);
}
.tab-control-item.active span{
  border-bottom: 3px solid var(--color-tint);
}
</style>